package com.haiyi.software.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.haiyi.software.app.R.string;
import com.haiyi.software.chat.WheelUbodyAdapter;

public class ActivityModifyUbody extends Activity {

	private WheelView wheel_ubody;

	private String ubody;

	private List<String> ubodyList = new ArrayList<String>();

	private String[] ubodys = { "猴", "熊", "狐", "狼", "狸" };

	private Button btn_saveback;

	private int selectIndex;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO 自动生成的方法存根
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_modify_ubody);

		getParameters();

		initComp();

		initData();
	}

	private void initData() {

		for (int i = 0; i < ubodys.length; i++) {
			ubodyList.add(ubodys[i]);
		}

		int index = ubodyList.indexOf(ubody);

		selectIndex = index == -1 ? 0 : index;

		// TODO 自动生成的方法存根
		this.wheel_ubody.setCurrentItem(selectIndex);
	}

	private void initComp() {
		// TODO 自动生成的方法存根
		this.wheel_ubody = (WheelView) this.findViewById(R.id.wheel_ubody);
		this.btn_saveback = (Button) this.findViewById(R.id.btn_saveback);

		this.wheel_ubody.setViewAdapter(new WheelUbodyAdapter(this));

		this.wheel_ubody.setCyclic(true);

		this.wheel_ubody.addScrollingListener(scrollListener);
		this.btn_saveback.setOnClickListener(saveClick);
	}

	OnWheelScrollListener scrollListener = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {
			// TODO 自动生成的方法存根

		}

		@Override
		public void onScrollingFinished(WheelView wheel) {

			selectIndex = wheel.getCurrentItem();

		}

	};

	private OnClickListener saveClick = new OnClickListener() {

		@Override
		public void onClick(View v) {

			Intent intent = new Intent();

			intent.putExtra("ubody", ubodyList.get(selectIndex));

			setResult(ActivityModifyInformation.SHOW_SUB_ACTIVITY_UBODY, intent);

			ActivityModifyUbody.this.finish();
		}
	};

	private void getParameters() {
		// TODO 自动生成的方法存根
		this.ubody = this.getIntent().getStringExtra("ubody");
	}

}
